<?php
// params: cat: comma separated objcat ids, limit: limit of results, output: normal|flyer, nonetext: text none in cats

include_once($cfgPaths['template'].'cms/app/includes/showDatesByCat.inc.php');

$cats = explode(",",$params['cat']);
$objects = $dba->getContentObjectsByCat($cats,"order by date_year, date_month, date_day");

$sth = '';
if (count($objects))
{
    $limitstr = '';
    if ($params['limit'])
        $limitstr = " limit ".$params['limit'];
    $sth = $udba->query("select distinct R1.element_id, title_text, teaser_text, body_text, date_year, date_month, date_day," .
            " R2.name As catname, flyer_href from ".$udba->tableforwarder.
            "_cmsPubType_freiraumdate R1, ".$udba->tableforwarder."_cmsObjCat R2, ".
            $udba->tableforwarder."_cmsElement R3 where R1.element_id=R3.element_id " .
            "and R2.id=R3.cat_id  and date_year * 10000 + date_month * 100 + date_day " .
            "< ".date("Ymd",(time() - 10*60*60))." and R1.element_id in (".join(',',$objects).") order by " .
            "date_year * 10000 + date_month * 100 + date_day desc $limitstr;");
}
if (is_object($sth) && $sth->num_rows())
{
    $rows = $sth->fetch_rows_array();
    for ($i = 0; $i < count($rows); $i++)
    {
        if ($params['output'] == 'flyer')
            withFlyer($rows[$i]);
        else
            withoutFlyer($rows[$i]);
    }
}
else
{
    print "<p>".$params['nonetext']."</p>";
}
?>